<?php
declare (strict_types=1);

namespace app\api\model;

use think\facade\Db;
use think\Model;

/**
 * @mixin \think\Model
 */
class CouponExchange extends Model
{
    //查询积分兑换表
    protected $table = "ea_coupon_exchange";

    //查询可兑换的物品展示
    public static function showGoods()
    {
        //展示积分兑换商城的优惠卷
        $data['coupon'] = Db::table('ea_coupon_exchange')
            ->alias('a')
            ->field('a.state as statea,b.state as stateb,b.*,a.*')
            ->join('preferential_settings b', 'a.coupon_id = b.id')
            ->where('a.state', 1)
            ->where('b.state', 0)
            ->select()->toArray();


        //展示积分兑换商城的商品
        $data['goods'] = Db::table('ea_coupon_exchange')
            ->where('goods_id', '>', 0)
            ->where('state', 1)
            ->where('status', 2)
            ->alias('a')
            ->join('mall_goods g', 'a.goods_id = g.id')
            ->select()->toArray();

        ///判断sql 查询数据不存在
        if (empty($data['goods']) && empty($data['coupon'])) {
            return json(['code'=>10500,'msg'=>'表数据为空']);
        }
        return $data;
    }





    //查询用户详情信息
    public static function shopDetails($id)
    {
        return self::where('id','=',"$id")
            ->find();
    }


}
